package design.mode.effective_java.chapter2.item2.pizza;

import java.util.Objects;


/**
 * @author mingde
 * @date 2021/8/2 23:25
 * @describe 标准的纽约风格的比萨, 必需的尺寸大小参数
 */
public class NyPizza extends Pizza {

    public enum Size {SMALL, MEDIUM, LARGE}

    private final Size size;

    public static class Builder extends Pizza.Builder<Builder> {
        private final Size size;

        public Builder(Size size) {
            this.size = Objects.requireNonNull(size);
        }

        /*子类的构建器中的构建方法声明为返回正确的子类*/
        @Override
        public NyPizza build() {
            return new NyPizza(this); // 协变返回类型
        }

        @Override
        protected Builder self() {
            return this;
        }
    }

    NyPizza(Builder builder) {
        super(builder);
        size = builder.size;
    }
    public enum Topping {HAM, MUSHROOM, ONION, PEPPER, SAUSAGE}
    public static void main(String[] args) {

        NyPizza pizza = new Builder(Size.SMALL)
                .addToppings(Pizza.Topping.MUSHROOM)
                .addToppings(Pizza.Topping.HAM)
                .build();
        System.out.println(pizza.size);
        Calzone calzone = new Calzone
                .Builder()
                .addToppings(Pizza.Topping.HAM)
                .sauceInside()
                .build();

    }
}
